home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / UsersDlgGeneral.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  9KB  |  309 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // UsersDlgGeneral.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "FileZilla server.h"
  24. #include "UsersDlgGeneral.h"
  25. #include "../misc/md5.h"
  26. #include "entersomething.h"
  27. #include "UsersDlg.h"
  28. #include "UsersDlgSpeedLimit.h"
  29.  
  30. #if defined(_DEBUG) && !defined(MMGR)
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Dialogfeld CUsersDlgGeneral 
  38.  
  39. CUsersDlgGeneral::CUsersDlgGeneral(CUsersDlg* pOwner) 
  40.     : CSAPrefsSubDlg(IDD)
  41.     , m_Comments(_T(""))
  42. {
  43.     m_pOwner = pOwner;
  44.     
  45.     //{{AFX_DATA_INIT(CUsersDlgGeneral)
  46.     m_bNeedpass = FALSE;
  47.     m_Pass = _T("");
  48.     m_nMaxUsersBypass = FALSE;
  49.     m_MaxConnCount = _T("");
  50.     m_IpLimit = _T("");
  51.     m_nEnabled = 0;
  52.     //}}AFX_DATA_INIT
  53.  
  54.     m_pUser = 0;
  55. }
  56.  
  57. CUsersDlgGeneral::~CUsersDlgGeneral()
  58. {
  59. }
  60.  
  61.  
  62. void CUsersDlgGeneral::DoDataExchange(CDataExchange* pDX)
  63. {
  64.     CSAPrefsSubDlg::DoDataExchange(pDX);
  65.     //{{AFX_DATA_MAP(CUsersDlgGeneral)
  66.     DDX_Control(pDX, IDC_MAXCONNCOUNT, m_cMaxConnCount);
  67.     DDX_Control(pDX, IDC_MAXUSERBYPASS, m_cMaxUsersBypass);
  68.     DDX_Control(pDX, IDC_NEEDPASS, m_cNeedpass);
  69.     DDX_Control(pDX, IDC_GROUP, m_cGroup);
  70.     DDX_Control(pDX, IDC_PASS, m_cPass);
  71.     DDX_Control(pDX, IDC_IPLIMIT, m_cIpLimit);
  72.     DDX_Check(pDX, IDC_NEEDPASS, m_bNeedpass);
  73.     DDX_Text(pDX, IDC_PASS, m_Pass);
  74.     DDX_Check(pDX, IDC_MAXUSERBYPASS, m_nMaxUsersBypass);
  75.     DDX_Text(pDX, IDC_MAXCONNCOUNT, m_MaxConnCount);
  76.     DDV_MaxChars(pDX, m_MaxConnCount, 9);
  77.     DDX_Text(pDX, IDC_IPLIMIT, m_IpLimit);
  78.     DDV_MaxChars(pDX, m_IpLimit, 9);
  79.     DDX_Control(pDX, IDC_USERS_GENERAL_ENABLE, m_cEnabled);
  80.     DDX_Check(pDX, IDC_USERS_GENERAL_ENABLE, m_nEnabled);
  81.     //}}AFX_DATA_MAP
  82.     DDX_Control(pDX, IDC_USERS_GENERAL_COMMENTS, m_cComments);
  83.     DDX_Text(pDX, IDC_USERS_GENERAL_COMMENTS, m_Comments);
  84.     DDV_MaxChars(pDX, m_Comments, 20000);
  85.     DDX_Control(pDX, IDC_FORCESSL, m_cForceSsl);
  86.     DDX_Check(pDX, IDC_FORCESSL, m_nForceSsl);
  87. }
  88.  
  89.  
  90. BEGIN_MESSAGE_MAP(CUsersDlgGeneral, CSAPrefsSubDlg)
  91.     //{{AFX_MSG_MAP(CUsersDlgGeneral)
  92.     ON_BN_CLICKED(IDC_NEEDPASS, OnNeedpass)
  93.     ON_CBN_SELCHANGE(IDC_GROUP, OnSelchangeGroup)
  94.     //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Behandlungsroutinen fⁿr Nachrichten CUsersDlgGeneral 
  99.  
  100. BOOL CUsersDlgGeneral::OnInitDialog() 
  101. {
  102.     CSAPrefsSubDlg::OnInitDialog();
  103.     
  104.     m_bNeedpass = FALSE;
  105.     m_Pass = _T("");
  106.     UpdateData(FALSE);
  107.     
  108.     m_cGroup.AddString(_T("<none>"));
  109.     for (CUsersDlg::t_GroupsList::iterator iter = m_pOwner->m_GroupsList.begin(); iter != m_pOwner->m_GroupsList.end(); iter++)
  110.         m_cGroup.AddString(iter->group);
  111.  
  112.     SetCtrlState();
  113.  
  114.     return TRUE;  // return TRUE unless you set the focus to a control
  115.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  116. }
  117.  
  118. void CUsersDlgGeneral::OnNeedpass() 
  119. {
  120.     UpdateData(TRUE);
  121.     m_cPass.EnableWindow(m_bNeedpass);
  122. }
  123.  
  124. CString CUsersDlgGeneral::Validate()
  125. {
  126.     UpdateData(TRUE);
  127.     if (m_bNeedpass && m_Pass == _T(""))
  128.     {
  129.         m_cPass.SetFocus();
  130.         return _T("Empty passwords are not allowed. Please enter a password!");
  131.     }
  132.     if (_ttoi(m_MaxConnCount) < 0 || _ttoi(m_MaxConnCount) > 999999999)
  133.     {
  134.         m_cMaxConnCount.SetFocus();
  135.         return _T("The maximum user count has to be between 0 and 999999999!");
  136.     }
  137.     if (_ttoi(m_MaxConnCount) < 0 || _ttoi(m_MaxConnCount) > 999999999)
  138.     {
  139.         m_cIpLimit.SetFocus();
  140.         return _T("The maximum user limit per IP has to be between 0 and 999999999!");
  141.     }
  142.     return _T("");
  143. }
  144.  
  145. void CUsersDlgGeneral::SetCtrlState()
  146. {
  147.     if (!m_pOwner->GetCurrentUser())
  148.     {
  149.         m_cEnabled.EnableWindow(FALSE);
  150.         m_cNeedpass.EnableWindow(FALSE);
  151.         m_cPass.EnableWindow(FALSE);
  152.         m_cGroup.EnableWindow(FALSE);
  153.         m_cMaxUsersBypass.EnableWindow(FALSE);
  154.         m_cMaxConnCount.EnableWindow(FALSE);
  155.         m_cIpLimit.EnableWindow(FALSE);
  156.         m_cComments.EnableWindow(FALSE);
  157.         m_cForceSsl.EnableWindow(FALSE);
  158.  
  159.         m_cGroup.SetCurSel(CB_ERR);
  160.  
  161.         UpdateData(FALSE);
  162.     }
  163.     else
  164.     {
  165.         m_cEnabled.EnableWindow(TRUE);
  166.         m_cNeedpass.EnableWindow(TRUE);
  167.         m_cPass.EnableWindow(TRUE);
  168.         m_cGroup.EnableWindow(TRUE);
  169.         m_cMaxUsersBypass.EnableWindow(TRUE);
  170.         m_cMaxConnCount.EnableWindow(TRUE);
  171.         m_cIpLimit.EnableWindow(TRUE);
  172.         m_cComments.EnableWindow(TRUE);
  173.         m_cForceSsl.EnableWindow(TRUE);
  174.         
  175.         OnNeedpass();
  176.     }
  177. }
  178.  
  179. void CUsersDlgGeneral::OnSelchangeGroup() 
  180. {
  181.     if (m_cGroup.GetCurSel() <= 0)
  182.     {
  183.         m_pUser->group = _T("");
  184.         UpdateData(TRUE);
  185.         m_pOwner->SetCtrlState();
  186.         if (m_nMaxUsersBypass == 2)
  187.             m_nMaxUsersBypass = 0;
  188.         if (m_nEnabled == 2)
  189.             m_nEnabled = 1;
  190.         UpdateData(FALSE);
  191.         m_cMaxUsersBypass.SetButtonStyle(BS_AUTOCHECKBOX);
  192.         m_cEnabled.SetButtonStyle(BS_AUTOCHECKBOX);
  193.         
  194.         m_pOwner->m_pSpeedLimitPage->UpdateData(TRUE);
  195.         CButton *pButton = reinterpret_cast<CButton *>(m_pOwner->m_pSpeedLimitPage->GetDlgItem(IDC_USERS_SPEEDLIMIT_SERVERBYPASS_DOWNLOAD));
  196.         if (pButton->GetCheck() == 2)
  197.             pButton->SetCheck(0);
  198.         pButton->SetButtonStyle(BS_AUTOCHECKBOX);
  199.  
  200.         pButton = reinterpret_cast<CButton *>(m_pOwner->m_pSpeedLimitPage->GetDlgItem(IDC_USERS_SPEEDLIMIT_SERVERBYPASS_DOWNLOAD));
  201.         if (pButton->GetCheck() == 2)
  202.             pButton->SetCheck(0);
  203.         pButton->SetButtonStyle(BS_AUTOCHECKBOX);
  204.         m_pOwner->m_pSpeedLimitPage->UpdateData(FALSE);
  205.     }
  206.     else
  207.     {
  208.         m_cGroup.GetLBText(m_cGroup.GetCurSel(), m_pUser->group);
  209.         m_cMaxUsersBypass.SetButtonStyle(BS_AUTO3STATE);
  210.         m_cEnabled.SetButtonStyle(BS_AUTO3STATE);
  211.  
  212.         ((CButton *)m_pOwner->m_pSpeedLimitPage->GetDlgItem(IDC_USERS_SPEEDLIMIT_SERVERBYPASS_DOWNLOAD))->SetButtonStyle(BS_AUTO3STATE);
  213.         ((CButton *)m_pOwner->m_pSpeedLimitPage->GetDlgItem(IDC_USERS_SPEEDLIMIT_SERVERBYPASS_UPLOAD))->SetButtonStyle(BS_AUTO3STATE);
  214.     }
  215. }
  216.  
  217. BOOL CUsersDlgGeneral::DisplayUser(t_user *pUser)
  218. {
  219.     m_pUser = pUser;
  220.  
  221.     if (!pUser)
  222.     {
  223.         m_bNeedpass = FALSE;
  224.         m_Pass = _T("");
  225.         m_nMaxUsersBypass = 0;
  226.         m_IpLimit = _T("");
  227.         m_MaxConnCount = _T("");
  228.         m_Comments = _T("");
  229.         m_nForceSsl = 0;
  230.  
  231.         UpdateData(FALSE);
  232.  
  233.         return TRUE;
  234.     }
  235.     
  236.     m_Pass = pUser->password;
  237.     m_cPass.SetModify(FALSE);
  238.     m_bNeedpass = pUser->password != _T("");
  239.     
  240.     if (pUser->group == _T("") || m_cGroup.SelectString(-1, pUser->group) == CB_ERR)
  241.     {
  242.         m_cMaxUsersBypass.SetButtonStyle(BS_AUTOCHECKBOX);
  243.         m_cEnabled.SetButtonStyle(BS_AUTOCHECKBOX);
  244.         m_cGroup.SetCurSel(0);
  245.         m_cForceSsl.SetButtonStyle(BS_AUTOCHECKBOX);
  246.     }
  247.     else
  248.     {
  249.         m_cMaxUsersBypass.SetButtonStyle(BS_AUTO3STATE);
  250.         m_cEnabled.SetButtonStyle(BS_AUTO3STATE);
  251.         m_cForceSsl.SetButtonStyle(BS_AUTO3STATE);
  252.     }
  253.     m_nEnabled = pUser->nEnabled;
  254.     m_nMaxUsersBypass = pUser->nBypassUserLimit;
  255.     CString str;
  256.     str.Format(_T("%d"), pUser->nUserLimit);
  257.     m_MaxConnCount = str;
  258.     str.Format(_T("%d"), pUser->nIpLimit);
  259.     m_IpLimit = str;
  260.     m_Comments = pUser->comment;
  261.     m_nForceSsl = pUser->forceSsl;
  262.  
  263.     UpdateData(FALSE);
  264.     
  265.     return TRUE;
  266. }
  267.  
  268. BOOL CUsersDlgGeneral::SaveUser(t_user *pUser)
  269. {
  270.     if (!pUser)
  271.         return FALSE;
  272.     
  273.     pUser->nEnabled = m_nEnabled;
  274.     pUser->password = m_Pass;
  275.     if (!m_bNeedpass)
  276.         pUser->password = _T("");
  277.     else if (m_cPass.GetModify() && m_Pass != _T(""))
  278.     {
  279.         char *tmp = ConvToNetwork(pUser->password);
  280.         if (!tmp)
  281.         {
  282.             tmp = new char[1];
  283.             *tmp = 0;
  284.         }
  285.         MD5 md5;
  286.         md5.update((unsigned char *)tmp, strlen(tmp));
  287.         delete [] tmp;
  288.         md5.finalize();
  289.         char *res = md5.hex_digest();
  290.         CString hash = res;
  291.         delete [] res;
  292.         pUser->password = hash;    
  293.     }
  294.     
  295.     pUser->nBypassUserLimit = m_nMaxUsersBypass;
  296.     pUser->nUserLimit = _ttoi(m_MaxConnCount);
  297.     pUser->nIpLimit = _ttoi(m_IpLimit);
  298.     if (m_cGroup.GetCurSel()<=0)
  299.         pUser->group = _T("");
  300.     else
  301.         m_cGroup.GetLBText(m_cGroup.GetCurSel(), pUser->group);
  302.  
  303.     pUser->comment = m_Comments;
  304.  
  305.     pUser->forceSsl = m_nForceSsl;
  306.     
  307.     return TRUE;
  308. }
  309.